<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js" ></script>
    <title>Title</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            background-color: #efedd6;
            width: 100%;
            height: 100%;
        }
        .mainDiv{
            width: 100%;
            height: 100%;
            background-color: white;
            /*position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);*/
        }
        .topDiv{
            width: 100%;
            height: 10%;
            background-color: #efedd6;
            position: sticky;
            top: 0;
        }
        #bodyDiv{
            width: 100%;
            height: 90%;
        }
        .manyDiv{
            background-color: steelblue;
            width: 90%;
            height: 27%;
            border-radius: 50px;
            margin: 8% 5% 8% 5%;
            text-align: center;
        }
    </style>

</head>
<body>
<div class="mainDiv">
    <div class="topDiv">
        <h1>会议审核</h1>
        <h1 id="newButton" onclick="ref()" value="${_csrf.token}">刷新</h1>
    </div>
    <div id="bodyDiv">

    </div>
</div>

</body>
<script>
    function ref(){
        $.ajax({
            type: "post",
            url: "http://dqm5nb.natappfree.cc/admin/queryList",
            dataType: "json",
            async:false,
            contentType: 'application/json',
            jsonp: 'callback',
            data:JSON.stringify({status: 0}),
            success: function (data) {
                var json =  data ;
                var  stl="";
                var arr=new Array();
                for(var i in json.data){
                    var date=json.data[i].aply.date;
                    var reason=json.data[i].aply.reason;
                    var phone=json.data[i].aply.phone;
                    var start=json.data[i].aply.start;
                    var end=json.data[i].aply.end;
                    var rid=json.data[i].aply.rid;
                    var userid=json.data[i].aply.userid;
                    stl+="<div class='manyDiv'><h1>会议室："+json.data[i].aply.rid+"</h1>"+
                        "<h1>时间:"+json.data[i].aply.date+"</h1>"+
                        "<h1>"+json.data[i].aply.start+"---"+json.data[i].aply.end+"</h1>"+
                        "<h1>申请人:"+json.data[i].aply.userid+"</h1>"+
                        "<h1>联系电话:"+json.data[i].aply.phone+"</h1>"+
                        "<button onclick='right()' id=i>不通过</button>"+
                        "<button>通过</button></div>";
                        var str= {
                            "Apply": {
                                "date": "2022-02-28",
                                "reason": "社团活动",
                                "phone": "18174678093",
                                "start": 8,
                                "end": 12,
                                "rid": "1-101",
                                "userid": "1905050117",
                                "status": -1
                            }
                        }
                        str.Apply.date=date;
                        str.Apply.reason=reason;
                        str.Apply.phone=phone;
                        str.Apply.start=start;
                        str.Apply.end=end;
                        str.Apply.rid=rid;
                        str.Apply.userid=userid;
                        arr[i]=str;
                }
                $("#bodyDiv").empty();
                $("#bodyDiv").append(stl);
                var btn=document.getElementsByTagName('button');
                for(var i=0;i<btn.length;i++){
                    (function(i){ //这个是function里i，即function的形参，也可以换成j，换成什么变量名都无所谓
                        btn[i].onclick=function(){
                            var j="";
                            if(i%2==1){
                                j=parseInt((i)/2);
                                arr[j].Apply.status=1;
                            }
                            if(i%2==0){
                                j=parseInt((i)/2);
                                arr[j].Apply.status=-1;
                            }
                             $.ajax({
                            type: "post",
                            url: "http://dqm5nb.natappfree.cc/admin/accept",
                            dataType: "json",
                            async: false,
                            contentType: 'application/json;charset=UTF-8' ,
                            jsonp: 'callback',
                            data: JSON.stringify(arr[j]),
                            success:function (da) {
                                var d=da;
                                for( i in d) {
                                    alert(d.status);
                                }
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                alert(XMLHttpRequest.status);
                                alert(XMLHttpRequest.readyState);
                                alert(textStatus);
                            }
                        });
                        }
                    })(i);//这是循环中的i,被作为参数传入
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        });
    }
</script>
</html>